import Dialog from "./Dialog.vue";
var mask = null;

// 传统方式模拟IDialog接口的行为，使用构造函数和原型链
function IDialog() {}

IDialog.prototype.show = function(dialogType, text) {
  return createDialog({ dialogType: dialogType, text: text });
};

IDialog.prototype.phone = function(openId) {
  return createDialog({ dialogType: "phone", openId: openId });
};

IDialog.prototype.dragVerify = function(DragVerifycallback) {
  return createDialog({ dialogType: "dragVerify", DragVerifycallback: DragVerifycallback });
};

// 创建弹框的通用函数
function createDialog(options) {
  return new Promise(function(resolve) {
    if (!mask) {
      notice = function() {
        resolve("");
      };
      mask = document.createElement("div");
      var child = document.createElement("div");
      mask.appendChild(child);
      
      // 假设Dialog组件已经全局注册，直接实例化并挂载
      var dialogInstance = new Vue({
        render: function(createElement) {
          return createElement(Dialog, { props: options });
        }
      }).$mount(child);
      
      document.body.appendChild(mask);
      document.body.style.overflow = "hidden";
    } else {
      notice = function() {
        resolve("");
      };
    }
  });
}

// 关闭弹框的函数
function closeDialog() {
  notice();
  document.body.style.overflow = "auto";
  if (mask) {
    mask.parentNode.removeChild(mask);
    mask = null;
  }
}

// 初始化notice为一个空函数
var notice = function() {};

let notice = () => { };
